<template>
  <el-dropdown @command="command">
    <svg-icon icon-class="language" />
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          command="zh"
          :disabled="$i18n.locale === 'zh'"
        >中文</el-dropdown-item>
        <el-dropdown-item
          command="en"
          :disabled="$i18n.locale === 'en'"
        >English</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
import cookieJs from 'js-cookie'
export default {
  name: 'Lang',
  inject: {
    reLoad: {
      type: Function
    }
  },
  methods: {
    command(command) {
      this.$i18n.locale = command
      cookieJs.set('lang', this.$i18n.locale)
      //this.$router.go(0) // 刷新页面
      this.reLoad() // 静默刷新
    }
  }
}
</script>

<style></style>
